const path = require("path");
const name = (process.env.VUE_APP_NAME = require("./package.json").name);
const { ENV } = process.env;

function resolve(dir) {
  return path.join(__dirname, dir);
}

var Config = {
  publicPath: "./",
  chainWebpack: (config) => {
    config.resolve.alias.set("@", resolve("src"));
  },
  devServer: {
    port: 9002,
    host: "0.0.0.0",
    headers: {
      "Access-Control-Allow-Origin": "*"
    }
  },
  configureWebpack: {
    output: {
      library: `${name}-[name]`,
      libraryTarget: "umd", // 把微应用打包成 umd 库格式
      jsonpFunction: `webpackJsonp_${name}`
    }
  }
};

if (ENV !== "development") {
  Config.configureWebpack.optimization = {
    splitChunks: {
      chunks: "all", //同步异步全都打包
      minSize: 30000, //打包的库或者文件必须大于这个字节才会进行拆分
      maxSize: 800 * 1024,
      minChunks: 1, //规定当模块在生成的js文件（trunk）中被调用过多少次的时候再进行拆分
      maxAsyncRequests: 5,
      maxInitialRequests: 3,
      automaticNameDelimiter: "~", //如果不写filename 默认名字 组名~[name]
      name: true
    }
  };
}

module.exports = Config;
